package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/6/5 9:29
 */
public class C203 {

    public static ListNode removeElements(ListNode head, int val) {
        ListNode tmp = new ListNode(-1);
        tmp.next = head;
        ListNode cur = head, pre = tmp;
        while (cur != null) {
            if(cur.val == val) {
                pre.next = cur.next;
            }else {
                pre = cur;
            }
            cur = cur.next;
        }
        return tmp.next;
    }

}
